<?php 
	$cmb_Mes=$_POST['txtMes'];
	$cmb_Agno = $_POST['txtAgno'];
	header('Content-type: application/vnd.ms-excel');
	header("Content-Disposition: attachment; filename=LibroHonorario".$cmb_Mes."-".$cmb_Agno.".xls");
	header("Pragma: no-cache");
	header("Expires: 0");
	require_once("../conexion/conexion.php");
	require_once("../Funciones/funciones_publicas.php");
	$fun = new funciones_publicas();
	$mes = $fun->SeleccionaMes($cmb_Mes);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
</head>

<body>
<?php
//honorario
$con = new Conexion();
$con2 = $con->conexionBD("fpproduccion");
$sql = "select 
		date_format(HFecha,'%d/%m/%Y') as fecha,
		HNum,
		UsuNombre,
		honorario.UsuRut,
		HMonto
		
		from honorario
		inner join usuario on
		usuario.UsuRut=honorario.UsuRut
		where month(HFecha)='".$cmb_Mes."' and year(HFecha)='".$cmb_Agno."'
		order by HFecha asc";
$resultado = mysql_query($sql) or die ($con->error_mysql("Error en la consulta".mysql_error()));
$fila = mysql_num_rows($resultado);
$con->cerrarBD();
if($fila >0)
{
?>
<table width="100%" border="1" cellpadding="0" cellspacing="0" >
<tr>
<td colspan="7" bgcolor="#CCCCCC"><div align="center" style="font-size:24px"><strong>Libro de Honorarios, correspondiente al mes de <?php echo $mes;?> del <?php echo $cmb_Agno;?></strong></div></td>
</tr>
<tr>
<td colspan="7">&nbsp;</td>
</tr>
<tr>
	<th width="12%" bgcolor="#CCCCCC">FECHA EMISION</th>
	<th width="11%" bgcolor="#CCCCCC">N&deg; BOLETA</th>
	<th width="27%" bgcolor="#CCCCCC">PROVEEDOR</th>
	<th width="13%" bgcolor="#CCCCCC">RUT</th>
	<th width="10%" bgcolor="#CCCCCC">MONTO</th>
	<th width="15%" bgcolor="#CCCCCC">10% RETENIDO</th>
	<th width="12%" bgcolor="#CCCCCC">TOTAL</th>
</tr>
<?php
$sumatoria = 0;
$sumaMonto = 0;
$sumaRetenido = 0;
//honorario
while($reg = mysql_fetch_array($resultado))
{
	$retencion = ($reg['HMonto']*0.10);
	$total = ($reg['HMonto']-$retencion);
	echo "<tr>";
	echo "<td width=\"12%\" class='facExenta'>".$reg['fecha']."</td>";
	echo "<td width=\"11%\" class='facExenta'>".$reg['HNum']."</td>";
	echo "<td width=\"27%\" class='facExenta'>".$reg['UsuNombre']."</td>";
	echo "<td width=\"13%\" class='facExenta'>".$reg['UsuRut']."</td>";
	echo "<td width=\"10%\" class='facExenta'>".number_format ($reg['HMonto'],0,',','.')."</td>";
	echo "<td width=\"15%\" class='facExenta'>".number_format ($retencion,0,',','.')."</td>";
	echo "<td width=\"12%\" class='facExenta'>".number_format ($total,0,',','.')."</td>";
	echo "</tr>";
	$sumatoria += $total;
	$sumaMonto += $reg['HMonto'];
	$sumaRetenido += $retencion;
}
?>
<tr>
	<td colspan="4"><strong>TOTAL</strong></td>
	<td><strong><?php echo number_format ($sumaMonto,0,',','.')?></strong></td>
	<td><strong><?php echo number_format ($sumaRetenido,0,',','.')?></strong></td>
	<td><strong><?php echo number_format ($sumatoria,0,',','.')?></strong></td>
</tr>
</table>
<?php 
}
?>
</body>
</html>
